package CSS::Utils::Walk;
use Moose;
use Carp;

extends 'CSS::Utils';

sub walk {
    my ($self , $cb , $tree) = @_;
      
    croak "No callback passed to walk sub"
        unless $cb;
      
    $tree ||= $self->tree;
      
    my @res = ();
      
    my $rv = $cb->( $tree );
      
    push @res , $rv if $rv;
      
      
    if ($tree->list) {
        foreach my $child ( @{$tree->list} ) {
            push @res , $self->walk( $cb, $child );
        }
    }
      
      #use Data::Dumper;
      #print Dumper $tree->list_get('1');
      
      #foreach my $child ( $tree->list_get ) {
      #      push @res , $self->walk( $cb, $child );
      #}
      
      #return unless $tree->{'list'};
      
    return @res;
}


1;
